import apis from '../../http/apis/apis'
export default {
    namespaced: true,
    state: {
        admins: []
        // //分页
        // pageInfo: {
        //     pageSize: 5,
        //     currentPage: 1,
        //     total: 0,
        //     pages: 0,
        // },
        // searchInfo: {
        //     type: "companyName",
        //     queryValue: "",
        // },
        // //当前页
        // currentPage: {}
    },
    mutations: {
        setAdmins(state, data) {
            state.admins = data
        },

        // //分页
        // setTotal(state, val) {
        //     state.pageInfo.pages = val.pages;
        //     state.pageInfo.total = val.total;
        // },
        // setPageSize(state, val) {
        //     state.pageInfo.pageSize = val;
        // },
        // setCurrentPage(state, val) {
        //     state.pageInfo.currentPage = val;
        // },

        // //搜索
        // setQueryValue(state, val) {
        //     state.searchInfo.queryValue = val;
        // },

        // //修改 
        // //保存当前页
        // setCurrentPage(state, data) {
        //     state.currentPage = data
        // }

    },
    actions: {
        //add
        async addAdmins({ commit, state }, admin) {
            return await apis.admins.addAdmins(admin)
        },

        //get
        async getAdmins({ commit, state }) {
            const data = await apis.admins.getAdmins()
            if (data.status) {
                console.log(data);
                commit('setAdmins', data.data)
            }
        },

        //update
        async editAdmins({ commit, state }, admin) {
            const data = await apis.admins.editAdmins(admin)
            if (data.status) {
                console.log('修改成功');
            } else {
                console.log('修改失败');
            }
        },

        //delete
        async deleteAdmins({ commit, state }, admin) {
            return await apis.admins.deleteAdmins(admin);
        },
        
        //switch
        async switchAdmins({ commit, state }, status) {
            return await apis.admins.switchAdmins(status);
        },

    },
}